import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/recipe/data/api/recipe_ecprotocol_api.dart';
import 'package:casdon/modules/recipe/data/repository/recipe_repository.dart';
import 'package:casdon/modules/recipe/providers/recipe_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class RecipeEcprotocolUsecase {
  final RecipeRepository _repository;

  const RecipeEcprotocolUsecase(this._repository);

  Future<ResponseRecipeEcprotocolApi?> execute({
    required String recipeId,
    required String pid,
  }) async {
    try {
      var ret = await _repository.getRecipeEcProtocol(recipeId, pid);
      if (ret == null) return null;
      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("RecipeEcprotocolUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("RecipeEcprotocolUsecase 失败");
    }
  }
}

final recipeEcprotocolUsecaseProvider = Provider<RecipeEcprotocolUsecase>((
  ref,
) {
  return RecipeEcprotocolUsecase(ref.read(recipeRepository));
});
